//
//  WhLoginViewController.m
//  IOSDemo
//
//  Created by wang on 13-1-24.
//  Copyright (c) 2013年 wang. All rights reserved.
//

#import "WhLoginViewController.h"
#import "Connect.h"
#import "WhTabBarViewController.h"


#define  DOMAIN   "192.168.34.69"
@interface WhLoginViewController ()

@end

@implementation WhLoginViewController
@synthesize _connectThread;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"WhLoginViewController" bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sender:(id)sender {
    
    _connectThread = [[NSThread alloc] initWithTarget:self
                                            selector:@selector(connectThread:)
                                              object:nil];
   // [_connectThread start];
    [self onLoginSuccess];
}

- (void)connectThread:(id) arg0{
    
    _connect = new Connect();
    _connect->registerConnect( self );
    _connect->login("h-wang", "395325941", "125.89.67.179");
    delete( _connect );
}

-(void) onConnect{
    NSLog(@"onConnect");
    [self performSelectorOnMainThread:@selector(onLoginSuccess)withObject:nil waitUntilDone:YES];
}


-(void) onDisconnect{
    NSLog(@"onDisconnect");
}

-(void) onLoginSuccess{
    NSLog(@"onLoginSuccess");
    
    
    WhTabBarViewController *ctrl = [[WhTabBarViewController alloc] initWithNibName:@"WhTabBarViewController" bundle:nil];
    
    //[self.view insertSubview:ctrl.view atIndex:0];
    [self.view addSubview:ctrl.view];
     
}

@end
